/*
 * @name: 
 * @Author: 卡比
 * @Date: 2024-04-26 21:20:13
 * @LastEditors: 卡比
 * @LastEditTime: 2024-05-10 20:39:25
 */
module.exports = {
    getLocation(){
        return new Promise((resolve, reject) =>{
            if (uni.getChannel().channel == 4 || uni.getChannel().channel==3){
                this.chooseLocation().then(res => {
                    resolve(res)
                })
                return 
            }
         
            console.log();
            uni.getLocation({
                success: (res) => {
                    uni.setStorageSync('getLocationType', 1)
                    this.getSSq(res.latitude, res.longitude).then(res => {
                        resolve(res)
                    })
                },
                fail: (err) => {
                    console.log(err);
                    uni.setStorageSync('getLocationType', 2)

                    this.chooseLocation().then(res=>{
                        resolve(res)
                    })
                }
            })
            
        })
    },
    chooseLocation(){
        return new Promise((resolve, reject) => {
            uni.chooseLocation({
                latitude: uni.getStorageSync("latitude"),
                longitude: uni.getStorageSync("longitude"),
                success: (res) => {
                    console.log(res);
                    this.getSSq(res.latitude, res.longitude).then(res=>{
                        resolve(res)
                    })
                },
                fail: (err) => {
                    console.log(err);
                    reject(err)
                }
            })

        })

    },
    getSSq(latitude, longitude){
      return  this.request({
            latitude, longitude
        }, "/homemaking/address/getssq").then(res => {
            res.data={
                ...res.data,
                latitude, longitude
            }
            return res
        })
    }
}